package icu.lookyousmileface.threadpool;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @author starrysky
 * @title: FixedThreadPool
 * @projectName Juc_Pro
 * @description: 固定线程池，Executors线程池创建工具
 * @date 2021/1/2910:12 下午
 */
public class FixedThreadPool {
    public static void main(String[] args) {
        //阿里规则不允许如此用executors创建线程池
        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);

        try {
            for (int i = 1; i <= 10; i++) {
                fixedThreadPool.execute(new FutureTask<>(()-> {
                    System.out.println(Thread.currentThread().getName()+"=>ok");
                    return "ok";}));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        fixedThreadPool.shutdown();
        }
    }
}
